package com.luxondata.module.system.entry;

import java.util.Collection;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity  
@Table(name="T_BD_USER")  
public class User implements UserDetails{

	private Long id;
	private String username;
	private String number;
	private String password;
	private User createUser;
	private Date createDate;
	private String apiKey;
	private String plainPassword;
	
	@Id  
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="T_BD_USER_SEQ")     
    @SequenceGenerator(name="T_BD_USER_SEQ",allocationSize=1,initialValue=1, sequenceName="T_BD_USER_SEQ")  
//	@Id  
//	@GeneratedValue 
	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}

	

	@Column(name="fnumber")
	public String getNumber() {
		return number;
	}


	public void setNumber(String number) {
		this.number = number;
	}


	public String getPassword() {
		return password;
	}


	public void setPassword(String password) {
		this.password = password;
	}

    @ManyToOne
    @JoinColumn(name="create_user_id")
	public User getCreateUser() {
		return createUser;
	}


	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@Temporal(TemporalType.DATE)
	public Date getCreateDate() {
		return createDate;
	}


	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}


	public String getApiKey() {
		return apiKey;
	}


	public void setApiKey(String apiKey) {
		this.apiKey = apiKey;
	}


	@Override
	@Transient
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return null;
	}


	@Override
	@Column(name="fname")
	public String getUsername() {
		return username;
	}


	public void setUsername(String username) {
		this.username = username;
	}


	@Override
	@Transient
	public boolean isAccountNonExpired() {
		return true;
	}


	@Override
	@Transient
	public boolean isAccountNonLocked() {
		return true;
	}


	@Override
	@Transient
	public boolean isCredentialsNonExpired() {
		return true;
	}


	@Override
	@Transient
	public boolean isEnabled() {
		return true;
	}
	
	@Transient
	public String getPlainPassword() {
		return plainPassword;
	}

	public void setPlainPassword(String plainPassword) {
		this.plainPassword = plainPassword;
	}
}
